using ApiLib.AppStart;
using ApiLib.Utils;

namespace ApiLib.Models;

/// <summary>
/// 结果对象外包装 where T : class
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseResponse<T>
{
    /// <summary>
    /// 状态
    /// 0-success
    /// x-fail
    /// </summary>
    public int code { get; set; }

    /// <summary>
    /// 消息
    /// </summary>
    public string msg { get; set; } = string.Empty;

    /// <summary>
    /// 数据
    /// </summary>
    public T? data { get; set; }

    /// <summary>
    /// 构造函数
    /// </summary>
    public BaseResponse()
    {
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    public BaseResponse(int code)
    {
        this.code = code;
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    public BaseResponse(int code, string msg) : this(code)
    {
        this.msg = msg;
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    public BaseResponse(int code, string msg, T? data) : this(code, msg)
    {
        this.data = data;
    }

    /// <summary>
    /// 成功
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static BaseResponse<T> Success(string msg, T obj)
    {
        return new BaseResponse<T>(GlobalConfig.BaseResponseCode.Success, msg, obj);
    }

    /// <summary>
    /// 成功
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static BaseResponse<T> Success(T obj)
    {
        return Success("", obj);
    }

    /// <summary>
    /// 失败
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static BaseResponse<object> Failed(string msg, object? obj = null)
    {
        return new BaseResponse<object>(GlobalConfig.BaseResponseCode.Failed, msg, obj);
    }
}

/// <summary>
/// 返回集合
/// </summary>
/// <typeparam name="T"></typeparam>
public class ListResponse<T>
{
    /// <summary>
    /// 总数
    /// </summary>
    public int TotalCount { get; set; }

    /// <summary>
    /// 当前分页的数据
    /// </summary>
    public List<T> List { get; set; } = new();
}

/// <summary>
/// 分页参数
/// </summary>
public class PageParam
{
    /// <summary>
    /// 页码
    /// </summary>
    public int PageIndex { get; set; } = 1;

    /// <summary>
    /// 大小
    /// </summary>
    public int PageSize { get; set; } = 10;
}

/// <summary>
/// 通用查询参数
/// </summary>
public class CommonParam : PageParam
{
    /// <summary>
    /// 关键字
    /// </summary>
    public string Keyword { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 初始化时间，开始时间是当天00:00:00，结束时间是当天23:59:59
    /// </summary>
    public void InitTimeAsDay()
    {
        StartTime = StartTime.DayStart();
        EndTime = EndTime.DayEnd();
    }
}

/// <summary>
/// 类型和值
/// </summary>
public class BaseTextValue
{
    /// <summary>
    /// 
    /// </summary>
    public BaseTextValue()
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="text"></param>
    /// <param name="value"></param>
    public BaseTextValue(string text, string value)
    {
        Text = text;
        Value = value;
    }

    /// <summary>
    /// 名称
    /// </summary>
    public string Text { get; set; } = "";

    /// <summary>
    /// 值
    /// </summary>
    public string Value { get; set; } = "";
}

/*/// <summary>
/// 状态码
/// </summary>
public enum BaseStatusCodes
{
    /// <summary>
    /// 成功
    /// </summary>
    Success = 0,

    /// <summary>
    /// 错误
    /// </summary>
    Error = 1,

    /// <summary>
    /// 认证失败
    /// </summary>
    AuthenticationFailure = 401,

    /// <summary>
    /// 未授权访问
    /// </summary>
    UnauthorizedAccess = 403,
}*/